Skip to content

Add math module.#91

Merged
tychedelia merged 5 commits intoprocessing:mainfrom
tychedelia:glam
Mar 23, 2026
Merged

Add math module.#91
tychedelia merged 5 commits intoprocessing:mainfrom
tychedelia:glam

Conversation

@tychedelia
Copy link
Member

Wraps glam in Python, allowing users to call most processing methods as either: foo(1.0, 3.0, 4.0) or foo(vec2(1.0, 3.0, 4.0)).

Allowing both is helpful -- users can use the vec types to do linalg stuff and avoid having to pass things as v.x, v.y, v.z, etc.

Converts most internal processing_render APIs to use glam rather than explicit f32 args. We should have done this from the start and avoids unnecessary conversions.

We don't currently have matrices here, but they can be added later.

@tychedelia tychedelia requested a review from catilac March 21, 2026 19:23
Copy link
Contributor

@catilac catilac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! i have a question and would love the macro you wrote to have a little bit of documentation please!

Comment on lines +7 to +11
if val == 0.0 {
0.0f32.to_bits().hash(state);
} else {
val.to_bits().hash(state);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oo very curious about this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handles positive and negative zero in IEEE floats by treating them the same. Hashing a Vec4 is probably a bit sketchy (and glam does not impl Hash on the Rust side) but is very convenient for quick-and-dirty (AKA art).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AH the pos and neg IEEE float. thank you!

Comment on lines +89 to +97
macro_rules! impl_py_vec {
(
$name:ident, $py_name:literal, $n:literal,
[$(($field:ident, $set_field:ident, $idx:literal)),+],
$glam_ty:ty
$(, extra { $($extra:tt)* })?
) => {
#[pyclass(name = $py_name, from_py_object)]
#[derive(Clone, Debug)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add some documentation here? i'm still a macro_rules! bb

@tychedelia tychedelia merged commit 4dedf93 into processing:main Mar 23, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants